package org.mathcloud.math.core.generic.quantity;

import org.mathcloud.math.core.common.operator.QuantityObjectOperation;
import org.mathcloud.math.core.common.quantity.ComplexNumber;
import org.mathcloud.math.core.common.quantity.RealNumber;
import org.mathcloud.math.core.common.signature.QuantityObjectSignature;
import org.mathcloud.math.core.generic.signature.GenericQuantityObjectSignature;


public class GenericComplexNumber implements ComplexNumber
{

	public GenericComplexNumber()
	{
		realPart = 0.0;
		imagePart = 0.0;
		arg = 0.0;
		mod = 0.0;
		signature = GenericQuantityObjectSignature.getComplexNumberSignature();
	}

	public GenericComplexNumber(double real, double image)
	{
		realPart = real;
		imagePart = image;
		mod = Math.sqrt(realPart * realPart + imagePart * imagePart);
		arg = (mod == 0) ? 0 : Math.acos(realPart / mod);
		signature = GenericQuantityObjectSignature.getComplexNumberSignature();
	}

	public GenericComplexNumber(RealNumber in)
	{
		realPart = in.getValue();
		imagePart = 0.0;
		mod = Math.abs(realPart);
		arg = 0.0;
		signature = GenericQuantityObjectSignature.getComplexNumberSignature();
	}

	public GenericComplexNumber(ComplexNumber in)
	{
		realPart = in.getRealPart();
		imagePart = in.getImagePart();
		mod = Math.sqrt(realPart * realPart + imagePart * imagePart);
		arg = (mod == 0) ? 0 : Math.acos(realPart / mod);
		signature = GenericQuantityObjectSignature.getComplexNumberSignature();
	}

	@Override
	public QuantityObjectOperation getOperation()
	{
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public QuantityObjectSignature getSignature()
	{
		return signature;
	}

	@Override
	public Double getValue()
	{
		return mod;
	}

	@Override
	public Double getRealPart()
	{
		return realPart;
	}

	@Override
	public Double getImagePart()
	{
		return imagePart;
	}

	@Override
	public Double getArg()
	{
		return arg;
	}

	@Override
	public Double getMod()
	{
		return mod;
	}

	@Override
	public void setRealPart(double arg0)
	{
		realPart = arg0;
		mod = Math.sqrt(realPart * realPart + imagePart * imagePart);
		arg = (mod == 0) ? 0 : Math.acos(realPart / mod);		
	}

	@Override
	public void setImagePart(double arg0)
	{
		imagePart = arg0;
		mod = Math.sqrt(realPart * realPart + imagePart * imagePart);
		arg = (mod == 0) ? 0 : Math.acos(realPart / mod);		
	}

	@Override
	public void setArg(double arg0)
	{
		arg = arg0;
		realPart = mod*Math.cos(this.arg);
		imagePart = mod*Math.sin(this.arg);
	}

	@Override
	public void setMod(double arg0)
	{
		mod = Math.abs(arg0);
		realPart = mod*Math.cos(this.arg);
		imagePart = mod*Math.sin(this.arg);		
	}

	@Override
	public void setValue(double arg0)
	{
		setMod(arg0);		
	}
	
	private double realPart;
	private double imagePart;
	private double arg;
	private double mod;

  protected QuantityObjectSignature signature;


}
